package com.johann.leetcode;

import java.util.Arrays;

public class T26_RemoveDuplicates {

    public int removeDuplicates(int[] nums) {

        if (nums.length < 2) return nums.length;
        int i=0;
        int j=1;
        for (; i < nums.length && j< nums.length; i++,j++) {
            while (nums[j-1] == nums[j]) {
                j++;
                if(j>=nums.length){
                    break;
                }
            }
            if(j<nums.length){
                nums[i+1]=nums[j];
            }
        }
        System.out.println(Arrays.toString(nums));
        return j-1 == nums.length ? i : i+1 ;
    }

    public static void main(String[] args) {
        T26_RemoveDuplicates t26_demo01 = new T26_RemoveDuplicates();
        System.out.println(t26_demo01.removeDuplicates(new int[]{0, 0, 0, 0, 0}));
    }
}
